//
//  XUIPanelWindow.m
//  etionUI
//
//  Created by wjxfhxy on 15/9/30.
//  Copyright (c) 2015年 GuangZhouXuanWu. All rights reserved.
//

#import "XUIPanelWindow.h"

@implementation XUIPanelWindow
{
    //for ios9.0 bug
    UIWindow *_oldKeyWindow;
}

@synthesize responder = _responder;

-(instancetype)init
{
    self = [super initWithFrame:[UIScreen mainScreen].bounds];
    
    if([UIDevice isIOS9] == YES)
        _oldKeyWindow = [UIApplication sharedApplication].keyWindow;
    
    self.windowLevel = UIWindowLevelStatusBar + 1;
    [self makeKeyAndVisible];
    
    return self;
}

-(void)setResponder:(UIResponder *)responder
{
    [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    ReleaseObj(_responder);
    _responder = [responder retain_mm];
    
    if([responder isKindOfClass:[UIView class]])
        [self addSubview:(UIView*)_responder];
    else if([responder isKindOfClass:[UIViewController class]])
        [self addSubview:((UIViewController*)_responder).view];
}

- (void)dealloc
{
    if(_oldKeyWindow != nil)
       [_oldKeyWindow makeKeyAndVisible];
    _oldKeyWindow = nil;
    
    [_responder release_mm];
    superdealloc_mm;
}

@end
